﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Arizu.Repository;
using System.Data;

namespace AiRiZu
{
    public partial class ExitPerson : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        protected void Bind()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["PersonId"]))
                {
                    string personid = Request.QueryString["PersonId"].ToString();

                    DataTable dt = Arizu.Repository.Main.CreateInstance().GetPersonInfo(personid);

                    if (dt.Rows.Count > 0)
                    {
                        this.xing.Text = dt.Rows[0]["Xing"].ToString();
                        this.ming.Text = dt.Rows[0]["Ming"].ToString();
                        this.Email.Text = dt.Rows[0]["Email"].ToString();
                        this.Sex.SelectedValue = dt.Rows[0]["Sex"].ToString();
                        this.School.Text = dt.Rows[0]["School"].ToString();
                        this.Adress.Text = dt.Rows[0]["Adress"].ToString();
                        this.Work.Text = dt.Rows[0]["Work"].ToString();
                        this.MobileTelephone.Text = dt.Rows[0]["MobileTelephone"].ToString();
                        this.TelephoneBack.Text = dt.Rows[0]["TelephoneBack"].ToString();
                        this.MyDesc.Text = dt.Rows[0]["MyDesc"].ToString();
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }


        }


        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {

                //更新数据
                if (!string.IsNullOrEmpty(Request.QueryString["PersonId"]))
                {
                    string personid = Request.QueryString["PersonId"].ToString();
                    string sql = "update PersonInfo set Xing='" + this.xing.Text + "',Ming='" + this.ming.Text + "',Email='" + this.Email.Text;
                    sql += "',Sex='" + this.Sex.SelectedValue + "',School='" + this.School.Text + "',Adress='" + this.Adress.Text;
                    sql += "',Work='" + this.Work.Text + "',MobileTelephone='" + this.MobileTelephone.Text + "',TelephoneBack='" + this.TelephoneBack.Text + "',MyDesc='" + this.MyDesc.Text + "' where PersonId=" + personid;
                    int i = Main.CreateInstance().SavePersonInfo(sql);
                    if (i > 0)
                    {
                        Arizu.Repository.Message.Alertback("保存成功！");
                    }
                    else
                    {
                        Arizu.Repository.Message.Alertback("保存失败！");
                    }
                }
                //创建会员
                else
                {
                    string sql = "insert into PersonInfo(Xing,Ming,Email,MobileTelephone,Pass,Sex,School,Adress,Work,TelephoneBack,MyDesc)values('" + this.xing.Text + "','" + this.ming.Text + "','" + this.Email.Text + "','" + this.MobileTelephone.Text + "','123456','" + this.Sex.SelectedValue + "','" + this.School.Text + "','" + this.Adress.Text + "','" + this.Work.Text + "','" + this.TelephoneBack.Text + "','" + this.MyDesc.Text + "')";

                    int i = Main.CreateInstance().InsertPersonInfo(sql);
                    if (i > 0)
                    {
                        Arizu.Repository.Message.Alertback("创建会员成功！");
                    }
                    else
                    {
                        Arizu.Repository.Message.Alertback("创建会员失败！");
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
